home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1991: Code Warrior / bincue / Code Warrior.bin / Tools & Apps (Moof!) / Networking & Communications / The NetWork Project / Examples (Sources) / TrivialLookUp.p < prev    next >
Encoding:
Text File  |  1991-06-20  |  4.2 KB  |  191 lines  |  [TEXT/MPS ]

  1. {file TrivialLookUp. This is a sample implementation for a trivial look-up system. 
  2. Include a reference to this file and unit in your "uses" clause, compile and link 
  3. to TrivialLookUp.p.o before linking to NetWorkLib.o.
  4.  
  5. Trivial solutions: 
  6.     Register:     we do not register at all. Hence we can only be addressed, if a local NetWork
  7.                 processor knows us.
  8.     SetSearch:     we only default search allowed.
  9.     Active:        always claim true.
  10.     Random:        return broadcast address
  11.     Next:        return local address
  12.     }
  13.  
  14. {     © Copyright 1991 The NetWork Project, StatLab Heidelberg.   }
  15. {     © Copyright 1991 G. Sawitzki, Heidelberg.   }
  16.  
  17. unit NetWorkLookup;
  18.  
  19. interface
  20.  
  21. { The compile time variables NlServer and NlClient are only included to make
  22. comparisons with full implementations easier}
  23. { use "pascal -d NlServer=false" if you don´t want to register your own names }
  24.  
  25. {$IFC Undefined NlServer}
  26. {$SETC NlServer:=true}
  27. {$ENDC}
  28.  
  29. { use "pascal -d NlClient=false" if you don´t want to look for other programs }
  30.  
  31. {$IFC Undefined NlClient}
  32. {$SETC NlClient:=true}
  33. {$ENDC}
  34.  
  35. uses    Types,
  36.         Errors,
  37.         NetWork;
  38.  
  39.  
  40. {$IFC UNDEFINED UsingAppletalk}
  41. type Str32 = String [32];
  42. {$ENDC}
  43.  
  44. {    =============================================================    }
  45.  
  46. {    name lookup - identication of possible partners }
  47.  
  48. const
  49.     nlVersion    = -31100;    { -- no appletalk version 48 or higher, could be removed }
  50.     nlTaskErr    = -31103;     { -- routines called in wrong order }
  51.     nlNotFound    = -31104;     { -- used internally }
  52.     nlDupReg    = -31105;     { -- called NlRegister twice }
  53.     nlNoReg        = -31106;     { -- called NlDeregister without NlRegister }
  54.     nlAtkOffErr = -31108;    { -- appletalk off, cannot use function }
  55.  
  56.  
  57.     nlLocal        = 0;    { can be used instead of local to denote this machine }
  58.     nlBroadcast    = -1;    { bradcast address, all of this cable }
  59.     
  60. function NlNode : longint;
  61.  
  62. {$IFC NlClient}
  63.  
  64.  
  65. function NlSetSearch (NlName, NlType, NlZone : Str32) : OSErr;
  66.  
  67. {    start/stop of NL task }
  68.  
  69. function NlStart : OSErr;
  70. function NlStop : OSErr;
  71.  
  72. function NlCount : integer;    { or OSErr, if error, NlCount returns the number of partners found. }
  73. function NLActive (who:longint) : boolean;    { is who still on the list ? }
  74. function NLRandom : longint; { any partner. returns 0 on error.}
  75. function NLNext(after:longint) : longint;    { next partner. NLNext(0) retrurns first. returns 0 on error. }
  76. function NlTask : OSErr;        { call this function periodically }
  77. function NlGetSleep : longint;        { time that may elapse until next call to NlTask  }
  78.  
  79. {$ENDC}
  80.  
  81. {$IFC NlServer}
  82.  
  83. {    register a server, pass '' to use choosername, only one entity can be registered }
  84.  
  85. function NlRegister (NlName, NlType : Str32) : OSErr;
  86. function NlDeregister : OSErr;
  87.  
  88. {$ENDC}
  89.  
  90. function NlInit : OSErr;
  91. function NlExit : OSErr;
  92.  
  93. implementation
  94.  
  95.  
  96. {    =============================================================    }
  97.  
  98. {    name lookup - identication of possible partners }
  99.  
  100. { this function returns 0 if appletalk is down or driver/appletalk transport not installed }
  101.  
  102. function NlNode : longint;
  103. begin
  104.     NlNode := 0;
  105. end;
  106.  
  107. {$IFC NlServer}
  108.  
  109. function NlRegister : OSErr;
  110. begin
  111.     NlRegister:=noErr;
  112. end;
  113.  
  114. function NlDeregister : OSErr;
  115. begin
  116.     NlDeregister:=noErr;
  117. end;
  118. {$ENDC}
  119.  
  120. {$IFC NlClient}
  121. function NlSetSearch (NlName, NlType, NlZone : Str32) : OSErr;
  122. {trivial implementation checks whether parameters correspond to defaults =
  123. '=:Network Processor@*' }
  124. begin
  125.     if (NlName<>'=') | (NlType<> 'Network Processor') | (NlZone <>'*')
  126.     then {not default search target}
  127.         NlSetSearch := nlNotFound {error code recycled}
  128.     else
  129.         NlSetSearch := noErr;
  130. end;
  131.         
  132.  
  133. function NlStart : OSErr;
  134. begin
  135.      NlStart := noErr; 
  136. end;
  137.  
  138. function NlStop : OSErr;
  139. begin
  140.     NlStop := noErr;
  141. end;
  142.  
  143. function NlCount : integer;
  144. begin
  145.     NlCount := 0;
  146. end;
  147.     
  148. function NLActive(who:longint):boolean;
  149. begin
  150.     NlActive:=true
  151. end;
  152.  
  153. function NLRandom:longint;
  154. begin
  155.         NLRandom:=nlBroadcast;
  156. end;
  157.  
  158. function NLNext(after:longint):longint;
  159. var scr,NrOthers:integer;
  160. begin
  161.         NLNext:= 0;
  162. end;
  163.  
  164. function NlTask : OSErr;        { call this function periodically }
  165. begin
  166.     NlTask:=NoErr;
  167. end;
  168.  
  169. function NlGetSleep : longint;        { time that may elapse until next call to NlTask  }
  170. begin
  171.     NlGetSleep:=maxlongint;
  172. end;
  173.  
  174. {$ENDC}
  175.  
  176. {    =============================================================    }
  177.  
  178.  
  179. function NlInit : OSErr;
  180. begin
  181.     NlInit:=NoErr;
  182. end;
  183.  
  184. function NlExit : OSErr;
  185. begin
  186.     NlExit:=NoErr;
  187. end;
  188.  
  189.  
  190. end.
  191.